package org.springcloud.wisdom.amusement.login.loginmsg.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springcloud.wisdom.amusement.login.loginmsg.entity.Teacher;

import java.util.List;

@Mapper
public interface AdminTeacherDao {
    //增加
    @Insert("insert into teacher(tid,tname,tpass,dept) values (#{tid},#{tname},#{tpass},#{dept})")
    public int addTeacher(Teacher teacher);
    //删除
    @Update("update teacher set del=1 where tid=#{tid}")
    public int delTeacher(String tid);
    //修改
    @Update("<script>" +
            "  update teacher" +
            "        <set>" +
            "            <if test=\"null!= tid\">" +
            "                tid =#{tid}," +
            "            </if>" +
            "            <if test=\"null!= tname\">" +
            "                tname =#{tname}," +
            "            </if>" +
            "            <if test=\"null!= tpass\">" +
            "                tpass =#{tpass}," +
            "            </if>" +
            "            <if test=\"null!= dept\">" +
            "                dept =#{dept}," +
            "            </if>" +
            "        </set>" +
            "        where tid =#{tid}" +
            "</script>")
    public int updateTeacher(Teacher teacher);
    //查询

    @Select("<script>" +
            "SELECT * FROM teacher" +
            "  <where>" +
            "    <if test=\"tname != null\">" +
            "      tname = #{tname}" +
            "    </if>" +
            "    <if test=\"dept != null\">" +
            "     dept = #{dept} " +
            "    </if>" +
            "    <if test=\"tid != null\">" +
            "     tid = #{tid} " +
            "    </if>" +
            "  and del=0"+
            "</where>"+
            "limit #{start},#{size}"+
            "</script>")
    public List<Teacher> getByCond(int start, int size, String tname, Integer dept, String tid);

    @Select("<script>" +
            "SELECT count(*) FROM teacher" +
            "  <where>" +
            "    <if test=\"tname != null\">" +
            "      tname = #{tname}" +
            "    </if>" +
            "    <if test=\"dept != null\">" +
            "     dept = #{dept} " +
            "    </if>" +
            "    <if test=\"tid != null\">" +
            "     tid = #{tid} " +
            "    </if>" +
            " and del=0 "+
            "</where>"+
            "</script>")
    public int countTeacher(String tname,Integer dept,String tid);
}
